package com.hao.netty.http;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpServerCodec;

/**
 * TODO
 * Channel初始化接口
 * @author 97472
 * @version 1.0
 * @date 2021/11/29 14:23
 */
public class HttpInitializer extends ChannelInitializer<SocketChannel> {

    @Override
    protected void initChannel(SocketChannel socketChannel) throws Exception {
        ChannelPipeline pipeline = socketChannel.pipeline();

        // 加入一个Netty提供的httpServerCodec codec——>coder decoder
        // HttpServerCodec时netty提供的一个用户编码和解码http请求的

        pipeline.addLast("myHttpServerCodec",new HttpServerCodec());
        pipeline.addLast("myHttpHandler",new HttpHandler());
    }

}
